package com.bearlair.ch5.latchandbarrier;

/**
 * 没什么用
 */
public class YieldTest extends Thread {
    public YieldTest(String name) {
        super(name);
    }

    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(getName() + ":" + i);
            if (i == 0) {
                System.out.println(getName() + " is yield");
                Thread.yield();
            }
        }
    }

    /**
     * 暂停当前正在执行的线程对象，并执行其他线程。
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Thread t1 = new Thread(new YieldTest("t1"));
        Thread t2 = new Thread(new YieldTest("t2"));
        t1.setPriority(Thread.MAX_PRIORITY);
        t1.start();
        t2.start();
    }
}

